<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/_fragments::head(~{::title})">
    <meta charset="utf-8">
    <!-- 设置移动端更好的适配以及预览 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>博客管理</title>
    <!-- 引入semantic-ui的css和js -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}"/>
</head>

<body>

<!--导航栏部分 -->
<nav th:replace="admin/_fragments::menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <!-- inverted是反转的意思，默认效果是圆角的，我们可以使用attached是去除圆角 -->
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui blue header item">Blog管理后台</h2>
            <a href="#" class="item menu-item m-mobile-hide"><i class="home icon"></i>博客</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <div class="right menu-item m-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img class="ui avatar image" src="../../static/images/huazai.png"/>
                        龙哥
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!--绑定css样式:手机端显示，电脑端隐藏
        绑定js：当点击的时候，上面的菜单栏显示和隐藏进行切换。
    -->
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>
<div class="ui container">
    <div class="ui right attached pointing menu">
        <a href="#" th:href="@{/admin/blogs}" class="active item">列表</a>
        <a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
    </div>
</div>


<!-- 存放主体内容 -->
<div class="m-padded-tb-big m-container-small">
    <div class="ui container">
        <form action="#" method="post" class="ui segment form">
            <input type="hidden" name="page">
            <div class="inline stackable fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type:${types}" th:data-value="${type.id}" th:text="${type.name}"
                                     class="item" data-value="1">错误日志
                                </div>
                            </div>
                        </div>
                        <!--清除分类中的数据-->
                        <button id="clear-btn" class="ui compact button" type="button">clear</button>
                    </div>
                </div>
                <div class="field">
                    <input type="checkbox" id="recommend" name="recommend">
                    <label for="recommend">推荐</label>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini blue basic icon button">
                        <i class="search icon"></i>搜索
                    </button>
                </div>
            </div>
        </form>
        <div id="table-container">
            <table th:fragment="blogList" class="ui compact blue table">
                <thead>
                <tr>
                    <th></th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,itemStart:${page.list}">
                    <td th:text="${itemStart.count}">1</td>
                    <td th:text="${blog.title}">失败是成功之母</td>
                    <td th:text="${blog.type.name}">认知升级</td>
                    <td th:text="${blog.recommend}?'是':'否'">是</td>
                    <td th:text="${blog.published}?'已发布':'草稿'">是</td>

                    <td th:text="${blog.updateTime}">2020-1-1</td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}"
                           class="ui mini blue basic button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"
                           class="ui mini red basic button">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="7">
                        <div class="ui mini right floated pagination menu" th:if="${page.totalPage}>1">
                            <!--th:attr="data-page=${page.number}-1"是thymeleaf模板的自定义属性的方式-->
                            <a onclick="page(this)" th:attr="data-page=${page.currPage}-1" th:unless="${page.currPage}==1"
                               class="item">上一页</a>
                            <a onclick="page(this)" th:attr="data-page=${page.currPage}+1" th:unless="${page.currPage==page.totalPage}"
                               class="item">下一页</a>
                        </div>
                        <a href="#" th:href="@{/admin/blogs/input}" class="ui mini green basic button">
                            新增
                            <i class="add icon"></i>
                        </a>
                    </th>
                </tr>
                </tfoot>
            </table>
        </div>
        <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示：</div>
            <p th:text="${message}">恭喜，操作成功！！！</p>
        </div>

    </div>
</div>


<!-- 存放底部footer -->
<!-- vertical:垂直的，默认情况下segment是圆角，-->
<footer th:replace="admin/_fragments::footer" class="ui inverted vertical segment m-padded-tb-big">
    <!--设置一个居中的容器-->
    <div class="ui center aligned container">
        <!--grid:垂直划分，默认是16份；
            inverted divided：采用分割线  -->
        <div class="ui inverted stackable divided grid">
            <!--存放左边的二维码-->
            <diV class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <!--rounded：设置图片为圆角-->
                        <img src="../../static/images/wechat.jpg" class="ui rounded image" alt="图片加载失败"
                             style="width: 100px;height: 100px;"/>
                    </div>
                </div>
            </diV>
            <!--存放最新博客的信息-->
            <diV class="three wide column">
                <h4 class="ui inverted header  m-text-spaced m-opacity-mini">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">早期的鸟儿有虫吃</a>
                    <a href="#" class="item">早期的虫儿被鸟吃</a>
                </div>
            </diV>
            <!--存放联系我的相关信息-->
            <diV class="three wide column">
                <h4 class="ui inverted header m-text-spaced m-opacity-mini">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">Email：p15194420545@163.com</a>
                    <a href="#" class="item">QQ：1753853993</a>
                </div>
            </diV>
            <!--右侧的论坛介绍-->
            <diV class="seven wide column">
                <h4 class="ui inverted header m-text-spaced m-opacity-mini">论坛show</h4>
                <p class=" m-opacity-mini">这是我的个人博客，会分享一些关于编程，写作，思考相关的内容，希望可以给来到这里的人有所帮助...</p>
            </diV>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2021 - 2022 code1997 Designed by code1997</p>
    </div>

</footer>


<!-- js文件依赖jquery，因此我们需要引入jquery -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>

<script type="text/javascript">
    $('.menu.toggle').click(function () {
        $('.menu-item').toggleClass('m-mobile-hide');
    });
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    function page(obj) {
        /*给隐藏域属性赋值*/
        $("input[type='hidden'][name='page']").val($(obj).data("page"));
        /*使用ajax来进行表单的提交*/
        loadData()

    }

    $(function () {
        $("#search-btn").click(function () {
            //搜索的时候将name=page清零
            $("[name='page']").val(0);
            loadData();
        });
    })

    /*使用jquery来发送请求*/
    function loadData() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()
        })

    }

    $(".message .close").on('click', function () {
        $(this).closest('.message').transition('fade');

    });

    $('#clear-btn').on('click', function () {
        $('.ui.type.dropdown').dropdown('clear');
    })

</script>
</body>
</html>
